package com.shengzai.zookeeper;

import org.apache.zookeeper.*;

import java.io.IOException;

public class ZookeeperCreateCode {
    public static void main(String[] args) throws IOException, InterruptedException, KeeperException {
        Watcher watcher = new Watcher(){
            @Override
            public void process(WatchedEvent event){
                System.out.println("process函数正在执行");
            }
        };
        ZooKeeper zooKeeper = new ZooKeeper("master:2181,node1:2181,node2:2181", 10000, watcher);
        //String path   创建节点位置。
        //byte data[]   节点内容
        //List<ACL> acl     OPEN_ACL_UNSAFE 创建的节点具有读写全部的权限
        //                  CREATOR_ALL_ACL 表示有写的权限
        //                  READ_ACL_UNSAFE 表示有读的权限
        //CreateMode
        //       PERSISTENT 普通节点，持久化节点
        //       PERSISTENT_SEQUENTIAL 普通序列化节点
        //       EPHEMERAL  临时节点
        zooKeeper.create("/second_node","fs".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);

        zooKeeper.close(5000);
    }
}
